	$("#tb").datagrid({
	   	url:"purchaselist",
	   	method:"get",
		columns:[[  
            {field:'Id',title:'全选',width:100,checkbox:true},      
	        {field:'purchaseId',title:'订单号',width:100,align:'right'},    
	        {field:'productId',title:'产品编号',width:100,align:'right'},    
	        {field:'productName',title:'产品名称',width:100,align:'right'}, 
	        {field:'productType',title:'产品类型',width:100,align:'right'},
			{field:'productNumber',title:'产品数量',width:100,align:'right'},
			{field:'productPieces',title:'单位 ',width:100,align:'right'}, 
			{field:'productPrices',title:'单价(元)',width:100,align:'right'}, 
			{field:'purchaser',title:'采购员',width:100,align:'right'}, 
			{field:'purchasedate',title:'采购时间',width:110,align:'right'},
			{field:'dealine',title:'到货时间 ',width:110,align:'right'},
			{field:'saveDate',title:'下单时间',width:110,align:'right'},
			{field:'purchaseLister',title:'审批人',width:100,align:'right'},
			{field:'remark',title:'备注 ',width:100,align:'right'},
			{field:'supplierId',title:'供货商编号 ',width:120,align:'right'},
	    ]],
	    fit:true,
		toolbar:[{
			iconCls: 'icon-edit',
			text:"编辑",
			handler:function(){
				edit();
			}
		}
		,{
			iconCls: 'icon-add',
			text:"添加",
			handler:function(){
				add();
			}
		},{
			iconCls: 'icon-search',
			text:"查询",
			handler:function(){
				select();
			}
		},
		{
			iconCls: 'icon-print',
			text:"打印",
			handler:function(){
				print();
			}
		}
		
		
		],
		onLoadSuccess:function(){//数据加载完毕之后触发事件..,想让数据端某列作为js按钮,就需要加载完数据后,给该列赋予easyui的类属性
			$("#btn_1").linkbutton({    
			    iconCls: 'icon-add'   
			});  
		},
		loadMsg:"亲，正在努力加载...，请耐心等候哦!!",
		singleSelect:true,
		fitColumns:true,
		pagination:true,
		rownumbers:true
	})
	
function print(){
	var row = $('#tb').datagrid('getSelected');	
	if (row&&row.remark=="未下单"){
		if(confirm("确定下单？")){
		location="pdf?purchaseId="+row.purchaseId;
		$('#tb').datagrid('reload');
		}
	}else{
		alert("该产品已下单");
	}
	
}
function add(){
	
	$('#win').dialog('open').dialog('setTitle','添加');
	$('#fm').form('clear');
	url = 'addPurchaseList'
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       }
function edit(){
	var row = $('#tb').datagrid('getSelected');
	if (row){
		$('#win').dialog('open').dialog('setTitle','编辑');
		$('#fm').form('load',row);	
		url = 'editPurchaseList';
	}
}
function saveUser(){
	$('#fm').form('submit',{
		url:url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){	 
			if (result=='1'){
				$.messager.show({
					title: 'Error',
					msg: "操作失败" 
				});
			} else {
				$('#win').dialog('close');		// close the dialog
				$('#tb').datagrid('reload');	// reload the user data
			}
		}
	});
}
function select(){
	$('#won').dialog('open').dialog('setTitle','查询订单');
}
function Search(){
	var  v = $("#ser").val();
	 $.get("SearchPurchaseList",
		   {purchaseId:v},
		   function(data1){
			$('#won').dialog('close'); 
			$('#butt').attr('disabled',"true");
			var data = eval("("+data1+")");
			$('#win').dialog('open').dialog('setTitle','订单');
			$('#fm').form('load',data);
		});
}
		